<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			const cnNum=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]
			const unit =new Array("萬","仟","佰","拾","亿","仟","佰","拾","萬","仟","佰","拾","元","角","分");
			function fun(){
				let num=document.getElementById("num").value
				num=num.trim()
				let reg=/^\d{1,13}(\.\d{1,})?$/
				if(!reg.test(num)){
					alert("数字格式错误")
					return;
				}
				let intPart;
				let decPart;
				var index=num.indexOf(".")
				if(index<0){
					intPart=num-0+""
					decPart="00"
				}else{
					intPart=num.substring(0,index)-0+""
					decPart=(num+"0").substr(index+1,2)
				}
				
				let res1=""
				for (var i = intPart.length; i>0;i=i-3) {
					if(i-3<=0){
						res1=intPart.substring(0,i)+res1
					}else{
						res1=","+intPart.substring(i-3,i)+res1
					}
				}
				document.querySelector("#num1").textContent=res1+"."+decPart
		
			
			let res2=""
			let money=intPart+decPart
			for (var i = money.length-1,j=unit.length-1;i>=0;i--,j--) {
				res2=cnNum[money[i]]+unit[j]+res2
			}
			document.querySelector("#num2").textContent=res2
			}
		</script>
	</head>
	<body>
		输入数字：<input type="text" id="num">
		<button onclick="fun()">转换</button><br>
		银行金额: <span id="num1"></span><br>
		大写金额: <span id="num2"></span>
	</body>
</html>
